﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SignalBox.Core.Model
{
    public class TrainInfo
    {

        public string Code
        {
            get
            {
                return Train.TrainCode;
            }
        }

        public Train Train
        {
            get;
            set;
        }

        public DateTime Entry
        {
            get
            {
                foreach (TrainStop stop in Train.Stops)
                {
                    if (stop.Action == TrainStop.TrainAction.ENTER)
                        return stop.Arrive;
                }
                return DateTime.MinValue;
            }
            
        }

        public string EntryPoint
        {
            get
            {
                foreach (TrainStop stop in Train.Stops)
                {
                    if (stop.Action == TrainStop.TrainAction.ENTER)
                        return stop.Location;
                }
                return "";
            }
        }
        public DateTime Exit
        {
            get
            {
                foreach (TrainStop stop in Train.Stops)
                {
                    if (stop.Action == TrainStop.TrainAction.EXIT)
                        return stop.Arrive;
                }
                return DateTime.MinValue;
            }
        }
        public string ExitPoint
        {
            get
            {
                foreach (TrainStop stop in Train.Stops)
                {
                    if (stop.Action == TrainStop.TrainAction.EXIT)
                        return stop.Location;
                }
                return "";
            }
        }

        public string State
        {
            get
            {
                if (Train.State == Model.Train.TrainState.ACCELERATING)
                    return "Accelerating";
                else if (Train.State == Model.Train.TrainState.BRAKING)
                    return "Braking";
                else if (Train.State == Model.Train.TrainState.LEFT)
                    return "Left Territory";
                else if (Train.State == Model.Train.TrainState.NOT_AVAILABLE)
                    return "Scheduled";
                else if (Train.State == Model.Train.TrainState.RUNNING)
                    return "Running";
                else if (Train.State == Model.Train.TrainState.STOPPED)
                    return "Scheduled stop";
                else if(Train.State == Model.Train.TrainState.WAITING_SIGNAL)
                    return "Waiting at signal (" + Train.HeadLocation.X.ToString() + " - " + Train.HeadLocation.Y.ToString() + ")";

                return "";
            }
        }
    }
}
